package cn.xydpeng.springframework.beans.factory.support;


import cn.xydpeng.springframework.core.io.DefaultResourceLoader;
import cn.xydpeng.springframework.core.io.ResourceLoader;
import cn.xydpeng.springframework.lang.Nullable;
import cn.xydpeng.springframework.util.Assert;

/**
 * @author xydpeng
 * @version v1.0
 * @date: 2022/10/13
 * @description:
 */
public abstract class AbstractBeanDefinitionReader implements BeanDefinitionReader {

    @Nullable
    private ResourceLoader resourceLoader;

    private final BeanDefinitionRegistry registry;

    public AbstractBeanDefinitionReader(BeanDefinitionRegistry registry) {
        Assert.notNull(registry, "registry must not null");
        this.registry = registry;
        if (registry instanceof ResourceLoader) {
            this.resourceLoader = (ResourceLoader) registry;
        }else {
            this.resourceLoader = new DefaultResourceLoader();
        }
    }

    @Override
    public ResourceLoader getResourceLoader() {
        return this.resourceLoader;
    }

    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @Override
    public BeanDefinitionRegistry getRegistry() {
        return this.registry;
    }
}
